package com.sk.ccflower.server.common.tcpManager;

import java.nio.channels.SelectionKey;
import java.util.Iterator;

import com.sk.ccflower.server.lib.sockUtils.nio.SocketServer;

public class TcpManagerServer extends SocketServer {
	
	public TcpManagerServer(int listenPort, Class<?> clsSession) throws Exception {
		super(listenPort, clsSession);
	}
	
	public synchronized TcpManagerSession findSession( String email ) {
		Object obj = null;
		SelectionKey key = null;
		TcpManagerSession session = null;
		Iterator<SelectionKey> itr = getSelector().getKeys().iterator();
		
		while ( itr.hasNext() ) {
			key = (SelectionKey)itr.next();
			if(!key.isValid()) continue;
			
			obj = key.attachment();
			if( obj instanceof TcpManagerSession ) {
				session = (TcpManagerSession) obj;
				if ( null == session.m_email )			return null;
				if ( session.m_email.equals(email) )	return session;
			}
		}
		
		return null;
	}
	
}
